<?php
    session_start();
    require_once('userlevel.php'); //Require/include the permissions file
    require_once('template.php'); //Require/include the template file
    require_once('functions.php'); //Require/include the functions file
    require_once('db.php'); //Require/include the file with the database connection information
     
    if (!$_SESSION['user_loggedin']) {
        die ("Not logged in... <script>document.location.href='login.php'</script>");
    } elseif (!($_SESSION['userlevel'] >= $userlevel['setuser'])) {
        die (errorpage ("Your user level is not high enough to use this feature!", 'Set User'));
    } else {
        //Connect to DB and connect to the database using db.php
        $db = new my_db;
        $id = strip_tags(mysql_escape_string($_GET['id']));
        $fileid = strip_tags(mysql_escape_string($_GET['fileid']));
         
        template_headtag("Assign edit #$id");
        template_header();
        template_left();
        if (!empty($id)) {
            echo "<div class='pageheadertext'>Assign edit #$id</div>";
            //See if a value has been given for the alias if not display the form
            if (isset($_POST['user'])) {
                $user = mysql_escape_string($_POST['user']);
                 
                $db->query("UPDATE history SET user='$user' WHERE id='$id'");
                echo "<div align='center'>Edit assigned<br/><a href='history.php?id=$fileid'>Back</a></div>";
                 
            } else {
                 
                echo "
                    <form method='post' action='setuser.php?id=$id&amp;fileid=$fileid'>
                    <div align = 'center'><br/>
                    Username to assign edit to: <input type='text' name='user'/>
                    <input type='submit' value='Update'/>
                    </div></form>
                    ";
            }
        } else {
            errorbox('Invaild ID!');
        }
        template_footer();
    }
?>
